<?php
require_once 'Database/SQLiteDB.php';
	class PositionDAL{
		const POSITION_CLASS_NAME = 'Position';
		private $databaseHandler;
		
		public function __construct(){
			$this->databaseHandler = new SQLiteDB();
		}
		
		public function GetAll(){
			$database = $this->databaseHandler->CreateConnection();
			
			$query = 'SELECT * FROM '.SQLiteDB::TABLENAME;
	 	

			$sth = $database->prepare($query);
			if(!$sth->execute()){
				die("Error when creating table");
			}

			$arr = array();
			while($object = $sth->fetchObject(PositionDAL::POSITION_CLASS_NAME)){
				$arr[] = $object;
			}
			
			return $arr;
			
		}
		
		public function GetByID($id){
			$database = $this->databaseHandler->CreateConnection();
			
			$query = 'SELECT * FROM '.SQLiteDB::TABLENAME.' WHERE producerID = :producerID';
			
			$sth = $database->prepare($query);
			
			$sth->bindParam(':producerID', $id, PDO::PARAM_INT);
			
			if(!$sth->execute()){
				die("Error when creating table");
			}

			$arr = array();
			while($object = $sth->fetchObject(PositionDAL::POSITION_CLASS_NAME)){
				$arr[] = $object;
			};
			
			return $arr;
			
		}
	}
?>